﻿using System;
using System.Collections.Generic;
using System.Windows.Messaging;

namespace Remoting.Reactive.Windowing
{
    public sealed class LocalMessagingFactory : ILocalMessagingFactory
    {
        public ILocalMessageSenderObservable CreateSender(string receiverName)
        {
            Guard.Requires<ArgumentException>(!string.IsNullOrEmpty(receiverName));
            var localMessageSender = new LocalMessageSender(receiverName);
            var sender = new LocalMessageSenderObservable(localMessageSender);
            return sender;
        }

        public ILocalMessageSenderObservable CreateSender(string receiverName, string receiverDomain)
        {
            Guard.Requires<ArgumentException>(!string.IsNullOrEmpty(receiverName));
            Guard.Requires<ArgumentException>(!string.IsNullOrEmpty(receiverDomain));
            var localMessageSender = new LocalMessageSender(receiverName, receiverDomain);
            var sender = new LocalMessageSenderObservable(localMessageSender);
            return sender;
        }

        public ILocalMessageReceiverObservable CreateReceiver(string receiverName)
        {
            Guard.Requires<ArgumentException>(!string.IsNullOrEmpty(receiverName));
            var localMessageReceiver = new LocalMessageReceiver(receiverName);
            var receiver = new LocalMessageReceiverObservable(localMessageReceiver);
            return receiver;
        }

        public ILocalMessageReceiverObservable CreateReceiver(string receiverName, ReceiverNameScope nameScope, IEnumerable<string> allowedSenderDomains)
        {
            Guard.Requires<ArgumentException>(!string.IsNullOrEmpty(receiverName));
            Guard.Requires<ArgumentNullException>(allowedSenderDomains != null);
            var localMessageReceiver = new LocalMessageReceiver(receiverName, nameScope, allowedSenderDomains);
            var receiver = new LocalMessageReceiverObservable(localMessageReceiver);
            return receiver;
        }
    }
}